<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI 对话界面</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
        }

        body {
            background-color: #f0f2f5;
            height: 100vh;
            display: flex;
            flex-direction: column;
        }

        .chat-container {
            max-width: 1200px;
            margin: 0 auto;
            width: 100%;
            height: 100vh;
            padding: 20px;
            display: flex;
            flex-direction: column;
        }

        .messages {
            flex: 1;
            overflow-y: auto;
            padding: 20px 0;
            display: flex;
            flex-direction: column;
            gap: 20px;
        }

        .message {
            display: flex;
            gap: 15px;
            max-width: 80%;
        }

        .message.user {
            align-self: flex-end;
            flex-direction: row-reverse;
        }

        .avatar {
            width: 40px;
            height: 40px;
            border-radius: 6px;
            background: #e5e7eb;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
        }

        .user .avatar {
            background: #007bff;
            color: white;
        }

        .bubble {
            padding: 12px 16px;
            border-radius: 8px;
            background: white;
            line-height: 1.6;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
            position: relative;
        }

        .user .bubble {
            background: #e6f3ff;  /* 浅蓝色背景 */
            color: #2d3748;       /* 深灰色文字 */
            border-radius: 8px 8px 0 8px;
            box-shadow: 0 2px 6px rgba(0,0,0,0.1);
        }

        .input-area {
            padding: 20px 0;
            background: white;
            border-top: 1px solid #e5e7eb;
        }

        .input-wrapper {
            max-width: 800px;
            margin: 0 auto;
            display: flex;
            gap: 10px;
            align-items: center;
        }

        #input {
            flex: 1;
            padding: 14px 18px;
            border: 2px solid #e5e7eb;
            border-radius: 12px;
            font-size: 16px;
            outline: none;
            transition: all 0.3s ease;
            min-height: 48px;
        }

        #input:focus {
            border-color: #007bff;
            box-shadow: 0 0 8px rgba(0,123,255,0.2);
        }

        button {
            padding: 12px 24px;
            background: #007bff;
            color: white;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            transition: opacity 0.2s;
        }

        #camera-btn {
            font-size: 24px;
            padding: 8px 16px;
            line-height: 1;
            min-width: 48px;
        }

        button:hover {
            opacity: 0.9;
        }

        .timestamp {
            font-size: 11px;
            color: #718096;
            margin-top: 6px;
        }

        .bubble img {
            max-width: 200px;
            height: auto;
            border-radius: 4px;
            display: block;
            margin: 8px 0;
        }
    </style>
</head>
<body>
    <div class="chat-container">
        <div class="messages" id="messages">
            <div class="message">
                <div class="avatar">AI</div>
                <div class="bubble">
                    您好！我是天津工业大学小助手，有什么可以帮您？
                    <div class="timestamp">2024-02-20 10:00:00</div>
                </div>
            </div>
        </div>
        <div class="input-area">
            <div class="input-wrapper">
                <input type="file" id="upload" accept="image/*" style="display: none;">
                <button type="button" onclick="document.getElementById('upload').click()" id="camera-btn">📷</button>
                <input type="text" id="input" placeholder="输入您的问题...">
                <button onclick="sendMessage()">发送</button>
            </div>
        </div>
    </div>

    <script>
        const input = document.getElementById('input');
        const messages = document.getElementById('messages');
        const upload = document.getElementById('upload');

        upload.addEventListener('change', function(e) {
            const file = e.target.files[0];
            if (!file) return;

            const reader = new FileReader();
            reader.onload = function(event) {
                addImageMessage(event.target.result, true);
                setTimeout(() => {
                    addMessage('已收到图片，正在识别...', false);
                }, 1000);
            };
            reader.readAsDataURL(file);
        });

        function formatDate(date) {
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, '0');
            const day = String(date.getDate()).padStart(2, '0');
            const hours = String(date.getHours()).padStart(2, '0');
            const minutes = String(date.getMinutes()).padStart(2, '0');
            const seconds = String(date.getSeconds()).padStart(2, '0');
            return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
        }

        function addImageMessage(dataUrl, isUser) {
            const messageDiv = document.createElement('div');
            messageDiv.className = `message ${isUser ? 'user' : ''}`;

            messageDiv.innerHTML = `
                <div class="avatar">${isUser ? '我' : 'AI'}</div>
                <div class="bubble">
                    <img src="${dataUrl}" alt="上传的图片">
                    <div class="timestamp">${formatDate(new Date())}</div>
                </div>
            `;

            messages.appendChild(messageDiv);
            messages.scrollTop = messages.scrollHeight;
        }

        input.addEventListener('keypress', (e) => {
            if (e.key === 'Enter') sendMessage();
        });

        function sendMessage() {
            const text = input.value.trim();
            if (!text) return;

            addMessage(text, true);
            input.value = '';

            setTimeout(() => {
                addMessage('这是AI的回复示例，实际需要接入API实现真实交互。', false);
            }, 1000);
        }

        function addMessage(text, isUser) {
            const messageDiv = document.createElement('div');
            messageDiv.className = `message ${isUser ? 'user' : ''}`;

            messageDiv.innerHTML = `
                <div class="avatar">${isUser ? '我' : 'AI'}</div>
                <div class="bubble">
                    ${text}
                    <div class="timestamp">${formatDate(new Date())}</div>
                </div>
            `;

            messages.appendChild(messageDiv);
            messages.scrollTop = messages.scrollHeight;
        }
    </script>
</body>
</html>

要接入真实AI服务，需要修改sendMessage函数中的setTimeout部分，替换为实际的API调用逻辑